{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from numpy import genfromtxt\n",
    "from sklearn import linear_model\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![tu](img/2.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[     nan      nan      nan      nan      nan      nan      nan      nan]\n",
      " [     nan   83.     234.289  235.6    159.     107.608 1947.      60.323]\n",
      " [     nan   88.5    259.426  232.5    145.6    108.632 1948.      61.122]\n",
      " [     nan   88.2    258.054  368.2    161.6    109.773 1949.      60.171]\n",
      " [     nan   89.5    284.599  335.1    165.     110.929 1950.      61.187]\n",
      " [     nan   96.2    328.975  209.9    309.9    112.075 1951.      63.221]\n",
      " [     nan   98.1    346.999  193.2    359.4    113.27  1952.      63.639]\n",
      " [     nan   99.     365.385  187.     354.7    115.094 1953.      64.989]\n",
      " [     nan  100.     363.112  357.8    335.     116.219 1954.      63.761]\n",
      " [     nan  101.2    397.469  290.4    304.8    117.388 1955.      66.019]\n",
      " [     nan  104.6    419.18   282.2    285.7    118.734 1956.      67.857]\n",
      " [     nan  108.4    442.769  293.6    279.8    120.445 1957.      68.169]\n",
      " [     nan  110.8    444.546  468.1    263.7    121.95  1958.      66.513]\n",
      " [     nan  112.6    482.704  381.3    255.2    123.366 1959.      68.655]\n",
      " [     nan  114.2    502.601  393.1    251.4    125.368 1960.      69.564]\n",
      " [     nan  115.7    518.173  480.6    257.2    127.852 1961.      69.331]\n",
      " [     nan  116.9    554.894  400.7    282.7    130.081 1962.      70.551]]\n"
     ]
    }
   ],
   "source": [
    "# 读入数据 \n",
    "data = genfromtxt(r\"longley.csv\",delimiter=',')\n",
    "print(data)  # nan的原因是字符，无法显示，genfromtxt只读取数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 234.289  235.6    159.     107.608 1947.      60.323]\n",
      " [ 259.426  232.5    145.6    108.632 1948.      61.122]\n",
      " [ 258.054  368.2    161.6    109.773 1949.      60.171]\n",
      " [ 284.599  335.1    165.     110.929 1950.      61.187]\n",
      " [ 328.975  209.9    309.9    112.075 1951.      63.221]\n",
      " [ 346.999  193.2    359.4    113.27  1952.      63.639]\n",
      " [ 365.385  187.     354.7    115.094 1953.      64.989]\n",
      " [ 363.112  357.8    335.     116.219 1954.      63.761]\n",
      " [ 397.469  290.4    304.8    117.388 1955.      66.019]\n",
      " [ 419.18   282.2    285.7    118.734 1956.      67.857]\n",
      " [ 442.769  293.6    279.8    120.445 1957.      68.169]\n",
      " [ 444.546  468.1    263.7    121.95  1958.      66.513]\n",
      " [ 482.704  381.3    255.2    123.366 1959.      68.655]\n",
      " [ 502.601  393.1    251.4    125.368 1960.      69.564]\n",
      " [ 518.173  480.6    257.2    127.852 1961.      69.331]\n",
      " [ 554.894  400.7    282.7    130.081 1962.      70.551]]\n",
      "#########\n",
      "[ 83.   88.5  88.2  89.5  96.2  98.1  99.  100.  101.2 104.6 108.4 110.8\n",
      " 112.6 114.2 115.7 116.9]\n"
     ]
    }
   ],
   "source": [
    "# 切分数据\n",
    "x_data = data[1:,2:] # 注意第2列开始，因为第1列是预测结果\n",
    "y_data = data[1:,1] # 第2行开始所有行，第1列\n",
    "print(x_data)\n",
    "print('#########')\n",
    "print(y_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.40875510204081633\n",
      "(16, 50)\n"
     ]
    }
   ],
   "source": [
    "# 创建模型\n",
    "# 默认生成50个值\n",
    "alphas_to_test = np.linspace(0.001, 1)  # 0.001到1，慢慢增大，50个值候选值，就是岭回归系数λ\n",
    "# 创建模型，保存误差值，RidgeCV岭回归交叉验证\n",
    "model = linear_model.RidgeCV(alphas=alphas_to_test, store_cv_values=True)  # store_cv_values存贮交叉验证的结果\n",
    "model.fit(x_data, y_data)  # 训练模型\n",
    "\n",
    "# 岭系数\n",
    "print(model.alpha_)  # 岭回归系数，判断测试50个系数中最好的保存\n",
    "# loss值\n",
    "print(model.cv_values_.shape)  \n",
    "# print(model.cv_values_)  # 16个数据组，每组50个岭系数的值\n",
    "# 16表示样本个数，每次取1个样本（就是第0行数据）做测试集，其余15做训练集，再第1行测试机，其余训练集，。。循环16次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAD8CAYAAABw1c+bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xl8XWd95/HPT/t2tW+2Vq+JHceJHSd2EoYSaCkESsLSGUKaFoaQtoQlFGZalk6npQx9zXSYgSlMahoKGUxYmkDTNkyANhSy2Fh2gtc4XuJFtmTJ2mXtur/+ca9tRZGsK/nqXume7/v1ui/de85z7/09Xr7n6DnPOcfcHRERCY60ZBcgIiKJpeAXEQkYBb+ISMAo+EVEAkbBLyISMAp+EZGAUfCLiASMgl9EJGAU/CIiAZOR7AKmUl5e7o2NjckuQ0Rk0di1a9c5d6+Ipe2CDP7GxkaampqSXYaIyKJhZidibauhHhGRgFHwi4gEjIJfRCRgFPwiIgGj4BcRCRgFv4hIwCj4RUQCJmWCPxx2/s8/H+ZnL7UnuxQRkQUtZYI/Lc3Y+rNj/MuLbckuRURkQUuZ4AeoKMymrW8o2WWIiCxoKRX8VaEc2nqHk12GiMiCllLBX1mYTVufgl9E5HJSK/hDkaEed092KSIiC9aMwW9mdWb2lJkdNLP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x/D0DfBb478BQIoubJ7H0+QPAl929C8Ddp74P5eIRS58dKIw+LwLOJLC+uHP3nwGdl2lyB/CwR2wHis1sSTxrWIzBXwOcmvC6ObpsyjbuPgb0AGUJqW5+xNLnid5PZI9hMZuxz2a2Aahz939MZGHzKJa/59XAajN7xsy2m9mbElbd/Iilz/8V+C0zawaeAD6cmNKSZrb/32dtMd6IZao998lTk2Jps5jE3B8z+y1gE/Ar81rR/Ltsn80sDfhfwHsTVVACxPL3nEFkuOd1RH6r+7mZrXP37nmubb7E0ue7gK+7+/80s5uB/xftc3j+y0uKec+vxbjH3wzUTXhdy6t/9bvYxswyiPx6eLlfrRa6WPqMmf0q8Gngbe4+nKDa5stMfQ4B64CfmtlxImOhjy/yA7yx/tv+e3cfdfeXgUNENgSLVSx9fj/wXQB3fw7IIXJNm1QV0//3K7EYg38nsMrMlplZFpGDt49PavM48DvR5+8C/sWjR00WqRn7HB32+Gsiob/Yx31hhj67e4+7l7t7o7s3Ejmu8TZ3b0pOuXERy7/tHxA5kI+ZlRMZ+jmW0CrjK5Y+nwTeAGBma4gEf3tCq0ysx4Hfjs7u2QL0uHtLPL9g0Q31uPuYmX0IeJIS0ZVmAAAAs0lEQVTIjICvuft+M/szoMndHwceIvLr4BEie/rvTl7FVy7GPv8PoAD4XvQ49kl3f1vSir5CMfY5pcTY5yeBN5rZAWAc+E/u3pG8qq9MjH3+OPBVM/sYkSGP9y7mHTkze4TIUF159LjFnwCZAO7+IJHjGLcDR4AB4H1xr2ER//mJiMgcLMahHhERuQIKfhGRgFHwi4gEjIJfRCRgFPwiIgGj4BcRCRgFv4hIwCj4RUQC5t8AnG4h4PEsMdsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画图\n",
    "# 岭系数跟loss值的关系，alphas_to_test横坐标岭系数的50个值，从0.001到1\n",
    "# model.cv_values_.mean交叉验证法后得到的loss的值，然后求平均值（16个值的）\n",
    "plt.plot(alphas_to_test, model.cv_values_.mean(axis=0)) # 画的蓝色曲线\n",
    "# 选取的岭系数值的位置，就是之前的0.40875510204081633。\n",
    "# 画出最小值的点，model.alpha_为横坐标\n",
    "plt.plot(model.alpha_, min(model.cv_values_.mean(axis=0)),'ro')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([88.11216213])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(x_data[2,np.newaxis]) # 第2行，加上维度，预测的结果88.11216213与88.2差不多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([90.84704905])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(x_data[3,np.newaxis]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
